<template>
	<view>
		<view v-if="data.tabType == 1">
			<uni-swiper-dot :style="{height:data.height+'px'}" class="swiperdotbox_a" :current="data.data.length"
				:mode="data.mode || 'default' ">
				<swiper easing-function="easeInCubic" :style="{height:data.height+'px'}" class="swiper-box" :autoplay="true"
					:current="swiperDotIndex" :indicator-dots="true" circular>
					<swiper-item v-for="(it, i) in data.data" :key="i">
						<image class="swiperImage" :src="it.url" mode="aspectFill" @click="gotosUrls(it)"></image>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		<view v-if="data.tabType == 2">
			<uni-swiper-dot :style="{height:data.height+'px'}" class="swiperdotbox_b" :current="data.data.length"
				:mode="data.mode || 'default' ">
				<swiper easing-function="easeInCubic" :style="{height:data.height+'px'}" class="swiper-box" :autoplay="true"
					:current="swiperDotIndex" :indicator-dots="true" circular>
					<swiper-item v-for="(it, i) in data.data" :key="i">
						<image class="swiperImage" :src="it.url" mode="aspectFill" @click="gotosUrls(it)"></image>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		<view v-if="data.tabType == 3">
			<!-- 			<z-swiper v-model="data.data" :options="optionsLoop">
				<z-swiper-item v-for="(item,index) in  data.data" :key="index">
					<image class="swiperImage" :src="item.url" ></image>
				</z-swiper-item>
			</z-swiper> -->
		</view>
	</view>

</template>
<script setup>
	import {
		ref,
		watch,
		computed
	} from 'vue';

	const props = defineProps({
		type: {
			type: Number,
			default: 1, // 0: 一排3个, 1: 一排4个, 2: 一排5个
		},
		data: {
			type: Object,
			default: () => {}
		}
	});
	let swiperDotIndex = ref(0)
	let optionsLoop = ref({
		loop: true,
		autoplay: true,
		effect: 'coverflow',
		slidesPerView: 1.5,
		centeredSlides: true,
		loopedSlides: 2,
		panorama: {
			depth: 150,
			rotate: 45,
		},

	})

	function gotosUrls(obj) {
		console.log(obj, "obj")
		if (obj.link == '') {
			// #ifndef  MP-WEIXIN
			uni.showToast({
				icon: 'none',
				title: '暂未开放'
			})
			return false;
			//  #endif
		}
		var Tab = Tab = ['pages/index/index', '/pages/cat/cat', '/pages/personal/index', '/pages/goods/category']
		if (Tab.indexOf(obj.link) != -1) {
			uni.switchTab({
				url: obj.link
			})
			return
		}
		//暂时对外部链接不考虑
		else if (obj.link.indexOf("www") >= 0 || obj.link.indexOf("http") >= 0 || obj.link.indexOf("https") >= 0) {
			uni.navigateTo({
				url: `/pages/company/skip?url=${url}`
			})
		} else {
			if (obj.goodsType == 1) {
				uni.navigateTo({
					url: `/subPackages/commodity/details?id=${obj.link}`
				})
			}
		}
	}

	function toUrl(link) {
		let url = link
		var Tab = Tab = ['pages/index/index', '/pages/cat/cat', '/pages/personal/index']
		if (url == '' || url == '1') {
			// #ifndef  MP-WEIXIN
			uni.showToast({
				icon: 'none',
				title: '暂未开放'
			})
			return false;
			//  #endif
		}
		if (Tab.indexOf(url) != -1) {
			uni.switchTab({
				url: url
			})
			return
		} else if (url.indexOf("www") >= 0 || url.indexOf("http") >= 0 || url.indexOf("https") >= 0) {
			uni.navigateTo({
				url: `/pages/company/skip?url=${url}`
			})
		} else {
			uni.navigateTo({
				url: url
			})
		}
	}
</script>


<style lang="scss">
	// 轮播1
	.swiperdotbox_a {
		margin: 30upx;

		.swiper-box {
			.swiperImage {
				width: 100%;
				height: 100%;
				border-radius: 30upx;
			}
		}
	}

	// 轮播2
	.swiperdotbox_b {
		.swiper-box {
			.swiperImage {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
